<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------

namespace app\backend\controller;
use \tpfcore\Core;
use think\facade\Session;
use app\common\controller\ControllerBase;

/**
 * Admin控制器基类
 */
class Admin extends ControllerBase
{
	protected $beforeActionList = [
        'authValidate' =>  ['except'=>'login'],
    ];

    protected function  authValidate(){
        !Session::has("backend_author_sign") && $this->redirect(url("Admin/login"));
    }
	
	public function login(){
		Session::has("backend_author_sign") && $this->redirect(url("Index/index"));
		IS_POST && $this->jump(Core::loadModel($this->name)->login($this->param));
        return $this->fetch('login');
	}

	public function logout(){
		$this->jump(Core::loadModel($this->name)->logout());
	}
	/*
		修改密码
	*/
	public function uppwd(){
		IS_POST && $this->jump(Core::loadModel($this->name)->uppwd($this->param));
        return $this->fetch('uppwd');
	}
	/*
		管理员管理
	*/
	public function index(){
		return $this->fetch("index",[
            'list'=>Core::loadModel($this->name)->getAdminList()
        ]);
	}
	/*
		添加管理员
	*/
	public function add(){
		IS_POST && $this->jump(Core::loadModel($this->name)->addAdmin($this->param));
		return $this->fetch("add",[
			"listRole"=>Core::loadModel("Role")->getRole()
		]);
	}
	/*
		编辑管理员
	*/
	public function edit(){
		IS_POST && $this->jump(Core::loadModel($this->name)->editAdmin($this->param));
		return $this->fetch("edit",[
			'id'=>$this->param['id'],
			"list"=>Core::loadModel($this->name)->getAdminList($this->param),
			"listRole"=>Core::loadModel("Role")->getRole()
		]);
	}
	/*
		管理员管理
	*/
	public function del(){
		$this->jump(Core::loadModel($this->name)->delAdmin($this->param));
	}
	/*
		权限操作
	*/
	public function priv(){
		IS_POST && $this->jump(Core::loadModel($this->name)->priv($this->param));
		return $this->fetch("priv",[
			'listUser'=>Core::loadModel($this->name)->getAdminList(['id'=>$this->param['id']],"id,username,privs"),
		]);
	}
	/*
		锁定用户操作
	*/
	public function lock(){
		$this->jump(Core::loadModel($this->name)->lock($this->param));
	}
}